<?
	$_SESSION['url'] = getURL();
	if($_SESSION['is_login'] != true){
		header("Location: ".$root."/dang-nhap/");
	}
	
	if(isset($_GET['rid'])){
		$rid = intval($_GET['rid']);
	}else{
		reHome($urlHome);
	}
	
	if(isset($_GET['act']) && ($_GET['act'] == 'xoa') ){
		$db->query("UPDATE ".$prefix."raovat SET rv_anhthehien = '' WHERE rv_id = '".$rid."'");
		header("Location: ".$root."/sua-tin-rao-vat/".$rid."/".$myString->vietdecode(loadRaoVat($rid))."");
	}
		
	if(isset($_POST['submit'])){
		$rv_tieude = addslashes($_POST['rv_tieude']);
		$rv_mota = addslashes($_POST['rv_mota']);
		$rv_loairaovat = $_POST['rv_loairaovat'];
		$rv_nguoidang = $_SESSION['uid'];
		
		//Hinhanh
		$DuongDanAnh_tmp = $upload->upload_file($PathFile,'rv_hinhanh');
		
		if($DuongDanAnh_tmp != ''){
			$filetype = $upload->file_type($DuongDanAnh_tmp);
			$upload->crop_image($imgWidth,$imgHeight,$PathFile . $DuongDanAnh_tmp,$filetype,$PathThumbFile .$DuongDanAnh_tmp);
			$DuongDanAnh = "'" . $DuongDanAnh_tmp . "'";
		}else{
			$DuongDanAnh = "`rv_anhthehien`";
		}	
		
		//		
		
		$txtQuocGia = $_POST['txtQuocGia'];
		$txtTinhThanh = $_POST['txtTinhThanh'];
		$rv_chitiet = addslashes($_POST['rv_chitiet']);
		$rv_thoigiandang = addslashes($_POST['rv_thoigiandang']);
		
		$update = "UPDATE ".$prefix."raovat SET `rv_loairaovat` = '".$rv_loairaovat."', `rv_tieude` = '".$rv_tieude."', `rv_mota` = '".$rv_mota."', `rv_anhthehien` = ".$DuongDanAnh.", `rv_quocgia` = '".$txtQuocGia."', `rv_tinhthanh` = '".$txtTinhThanh."',`rv_thoigiandang` = '".$rv_thoigiandang."', `rv_chitiet` = '".$rv_chitiet."' WHERE rv_id = '".$rid."'";
		
		//echo $update;
		$db->query($update);
		header("Location: ".$root."/chi-tiet-rao-vat/".$rid."/".$myString->vietdecode(loadRaoVat($rid)).""); 
	}
	
	
	////LOAD TIN RA
	
	$rs = $db->query("SELECT * FROM ".$prefix."raovat WHERE rv_id = '".$rid."' AND rv_hienthi = 1");
	$row = $db->fetch_array($rs);
	$rv_id = $row[rv_id];
	$rv_loairaovat = $row[rv_loairaovat];
	$rv_nguoidang = $row[rv_nguoidang];
	//
		if($rv_nguoidang != $_SESSION['uid']){reHome($urlHome);}
	//
	$rv_ten_nguoidang = tenNguoiDung($rv_nguoidang);
	$rv_tieude = $myString->unQuote(stripslashes($row[rv_tieude]));
	$rv_anhthehien = $PathThumbFile . $row[rv_anhthehien];
	$rv_mota = $myString->unQuote(stripslashes($row[rv_mota]));
	$rv_quocgia = $row[rv_quocgia];
	$rv_tinhthanh = $row[rv_tinhthanh];
	$rv_ngaydang = format_date($row[rv_thoigian]);
	$rv_thoigiandang = $row[rv_thoigiandang];
	$rv_chitiet = $myString->unQuote(stripslashes($row[rv_chitiet]));
	$rv_solanxem = $row[rv_solanxem];
	$rv_xemgannhat = format_date_time($row[rv_xemgannhat]); 
?>
<div id="linkPath">
       
<script language="javascript" type="text/javascript">
    function CheckVND()
    {
        if(document.getElementById("chkVND").checked==true)
        {
            document.getElementById("btnSave").style.display='';
            document.getElementById("btnSave_off").style.display='none';
        }
        else
        {
            document.getElementById("btnSave").style.display='none';
            document.getElementById("btnSave_off").style.display='';
        }
    }
</script>


<div class="linkPath">
    <div class="corner-round-01-top-right">
        <div class="corner-round-01-top-left">
            <div class="corner-round-01-top-bg"></div>
        </div>

    </div>
    <div class="corner-round-01-body">    
        <span style="float: left;"><a href="?">Trang chủ</a> &raquo; Đăng tin rao vặt</span>
        <span style="float: right;"><a title="Quay lại trang trước" class="link-back" href="javascript:void(0);" onclick="javascript:history.go(-1);">Quay lại</a></span>
        <div style="clear: both;"></div>
    </div>
    <div class="corner-round-01-bottom-right">

        <div class="corner-round-01-bottom-left">
            <div class="corner-round-01-bottom-bg"></div>
        </div>
    </div>   
</div>    
    </div>

<form action="" name="frmDangBan" id="frmDangBan" method="post" enctype="multipart/form-data" onsubmit="return funRaoVatChecker();">
    <!-- Main Page-Content { -->    
    <div id="page-content">                            
        
<div id="product-new">
    <div class="corner-round-02-top-right">

        <div class="corner-round-02-top-left">
            <div class="corner-round-02-top-bg"></div>
        </div>
    </div>
    <div class="corner-round-02-body" style="height:auto;overflow:hidden">            
        <div id="error" class="form-error-group" style="none: block;width:816px">            
        </div>
        <div class="product-new-inner">            
            <div class="product-top-right"><div class="product-top-left"><div class="product-top-bg"></div></div></div>
            <div class="product-body">                    
                1. Thông tin rao vặt <span style="font-size:8pt;color:Gray;font-weight:normal;">(<em>Vui lòng dùng tiếng Việt có dấu hoặc tiếng Anh, độ dài 40 ký tự</em>)</span>

            </div>
            <div class="product-bottom-right"><div class="product-bottom-left"><div class="product-bottom-bg"></div></div></div>
            <div style="margin-left:0px;text-align:left;margin-bottom:5px;margin-left:80px;margin-top:10px;font-size:10pt;">                
                <span class="notes" style="color:#666666;font-size:8pt;">
                    Tiêu đề : 
                </span>
            </div>

            <div style="text-align:left;font-size:10pt;margin-bottom:10px;margin-left:80px;">
                <input class="product-input-text" type="text" style="padding:3px;" id="rv_tieude" name="rv_tieude" value="<?=$rv_tieude?>"/>
            </div>
                
           <div style="margin-left:0px;text-align:left;margin-bottom:5px;margin-left:80px;margin-top:10px;font-size:10pt;">                
                <span class="notes" style="color:#666666;font-size:8pt;">
                    Mô tả ngắn :
                </span>
            </div>

            <div style="text-align:left;font-size:10pt;margin-bottom:10px;margin-left:80px;">  
                <input class="product-input-text2" type="text" id="rv_mota" name="rv_mota" value="<?=$rv_mota?>" />
            </div> 
			
			
			<div style="margin-left:0px;text-align:left;margin-bottom:5px;margin-left:80px;margin-top:10px;font-size:10pt;">                
                <span class="notes" style="color:#666666;font-size:8pt;">
                    Chọn loại rao vặt :
                </span>
            </div>

            <div style="text-align:left;font-size:10pt;margin-bottom:10px;margin-left:80px;">  
                <select style="margin:0" class="product-input-select" name="rv_loairaovat" id="rv_loairaovat">           
                    <option value=""></option>
				<?
					$rs = $db->query("SELECT * FROM ".$prefix."loairaovat WHERE rvc_hienthi = 1 AND rvc_id_cha = 0");
					while($row = $db->fetch_array($rs)){
					$c_ten = $myString->unQuote(stripslashes($row[rvc_ten]));
					$c_id = $row[rvc_id];
				?>	
                    <optgroup label="<?=$c_ten?>">
					<?
						$rs2 = $db->query("SELECT * FROM ".$prefix."loairaovat WHERE rvc_hienthi = 1 AND rvc_id_cha = '".$c_id."'");
						while($row2 = $db->fetch_array($rs2)){
						$c_id2 = $row2[rvc_id];
						$c_ten2 = $row2[rvc_ten];
					?>
						<option value="<?=$c_id2?>" <? if($rv_loairaovat == $c_id2){?> selected="selected" <? }?>><?=$c_ten2?></option>
					<? } ?>
					</optgroup>
				<? } ?>
                </select>
            </div> 
			
            
            
            <div class="product-new-control">            
                <div style="margin-left:50px;">                    
                    <p>
                        <label class="title">Ảnh thể hiện</label>

                        <span id="fileDiv">
                            <input name="rv_hinhanh" id="rv_hinhanh" type="file" class="file" accept="image/gif, image/jpeg, image/jpg" size="73" /><br />                            
                        </span>
                    </p>
					<p>
						<label class="title">&nbsp;</label>
						<span>
							<img src="<?=$root?>/<?=$rv_anhthehien?>" width="120" border="0" onerror="this.src='<?=$root?>/themes/images/noimg.jpg';"/> <a href="<?=$root?>/?mod=suatinraovat&rid=<?=$rv_id?>&act=xoa" style="font-weight:bold; text-decoration:none;">[ Xóa Hình ]</a>
						</span>
					</p>
                    <p>

                        <label class="title">&nbsp;</label>
                        <span class="notes" style="color:#666666;font-size:0.8em;">
                            Hỗ trợ file hình định dạng *.jpg, *.gif, *.png. Dung lượng file hình tối đa 1Mb.
                        </span>
                        <br class="clearBoth"/> 
                    </p>                    
                    <p>
                        <label class="title">Thời gian đăng</label>
						<input type="text" name="rv_thoigiandang" id="rv_thoigiandang" size="15" value="<?=$rv_thoigiandang?>" /> ngày

                    </p>
					<br style="line-height:5px;"/>
                    <p>
                        <label class="title">Quốc gia</label>
						
					<select id="txtQuocGia" name="txtQuocGia" style="width:100px;" onchange="ajaxSelect2Select('txtQuocGia','txtTinhThanh','<?=$root?>/loadTinhThanh.php','IdQuocGia');"> 
					<option value="-1">---Chọn---</option>
					<? 
						$rs = $db->query("SELECT * FROM ".$prefix."quocgia order by qg_id ASC");
						while($row = $db->fetch_array($rs)){
					?>
						<option value="<?=$row[qg_id]?>"><?=$row[qg_ten]?></option>
					<? } ?>
					</select>
					<script language="javascript">
					  var a = document.getElementById('txtQuocGia');
					 for(var i=0;i<a.length;i++)
					 {if(a[i].value=="<?=$rv_quocgia?>")
					 {a.selectedIndex=i;break;}}
				 	 </script>
					<label class="labelLine">Tỉnh/TP</label>
			        <select id="txtTinhThanh" name="txtTinhThanh">
						<option value="-1">---Chọn---</option>

						  <?
						if($IdQuocGia == ""){$IdQuocGia = $rv_quocgia;}
						  if($IdQuocGia) 
			
						  {
			
							$sql="select * from ".$prefix."tinhthanh where tt_maquocgia = '".$IdQuocGia."' order by tt_id ASC";
							$rs = $db->query($sql);
			
							if($db->num_rows($rs))
			
							{
			
								while($rows=$db->fetch_array($rs))
			
								{
			
								?>
			
								<option value="<?=$rows["tt_id"]?>"><?=$rows["tt_ten"]?></option>
			
								<?
			
								}
			
							}
			
						}
			
						?>

					</select>
				<script language="javascript">
			  	 var a = document.getElementById('txtTinhThanh');
				 for(var i=0;i<a.length;i++)
				 {if(a[i].value=="<?=$rv_tinhthanh?>")
				 {a.selectedIndex=i;break;}}
	  		   </script>
                    </p>
                                   
                </div>                
            </div>  
            <br class="clearBoth"/>  
            <div style="height:15px;font-size:0px;"></div>      
            <div class="product-top-right"><div class="product-top-left"><div class="product-top-bg"></div></div></div>
            <div class="product-body">                    
                4. Chi tiết rao vặt <span style="font-size:8pt;color:Gray;font-weight:normal;">(<em>Vui lòng dùng tiếng Việt có dấu hoặc tiếng Anh</em>)</span>
				
            </div>
            <div class="product-bottom-right"><div class="product-bottom-left"><div class="product-bottom-bg"></div></div></div>        
            <div class="product-new-control" style="margin-left:60px;">

               <textarea id="elm2" name="rv_chitiet" rows="15" cols="80" style="width: 80%"><?=$rv_chitiet?></textarea>

            </div>
                        
        </div>
         <div class="clearBoth" style="text-align: center;">
            <input name="btnPreview" onclick="javascript: confirmDelete('<?=$root?>/action.php?act=del_sanpham&u_id=<?=$t_nguoidang?>&id=<?=$pid?>');" id="btnPreview" src="<?=$root?>/themes/images/home/btnXoa.jpg" value="Xem trước" type="image">
            <input name="btnSave" onclick="javascript: return submitForm();" id="btnSave" src="<?=$root?>/themes/images/form/button-pm-message.jpg" value="Đăng bán" type="image">
        </div> 
		<br />  
        <div style="color:#888888;font-size:10pt;">
            (*) Nên và không nên khi rao vặt, xem <a target="_blank" href="javascript:void(0);">tại đây</a>
        </div>
    </div>
    <div class="corner-round-02-bottom-right">
        <div class="corner-round-02-bottom-left">

            <div class="corner-round-02-bottom-bg"></div>
        </div>
    </div>   
</div>
<div style="height:10px"> </div>
<div id="uploadDiv"></div>       
    </div>
    <div style="clear:both;"></div>      
    <!-- } Main Page-Content -->  
	<input type="hidden" name="submit" id="submit" value="submit" />
</form>
                
            </div>
